package com.ssy.lingxi.settle.accounts.controller;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.settle.accounts.model.vo.request.*;
import com.ssy.lingxi.settle.accounts.model.vo.response.*;
import com.ssy.lingxi.settle.accounts.service.IBusinessReconciliationRowService;
import com.ssy.lingxi.settle.accounts.service.IBusinessReconciliationService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 平台结算管理-业务对账-供应商
 * @author Houpengfei
 * @date 2021/12/6
 **/
@RestController
@RequestMapping("/settle/accounts/business/reconciliation")
public class BusinessReconciliationController extends BaseController {

    @Resource
    private IBusinessReconciliationService service;

    @Resource
    private IBusinessReconciliationRowService detailService;


    /**
     * 待对账列表
     * @author Saske
     */
    @RequestMapping(value = "/to/reconciliation/list",method = RequestMethod.GET)
    public Wrapper<PageData<ToBeReconciliationVO>> toBeReconciliationList(HttpServletRequest request,@Valid ToBeReconciliationListVO queryParameter){
        return service.toBeReconciliationList(getSysUser(request),queryParameter);
    }

    /**
     * 生成对账单数据
     * @author Saske
     */
    @RequestMapping(value = "/generate/reconciliation",method = RequestMethod.POST)
    public Wrapper<GenerateReconciliationVO> generateReconciliation(HttpServletRequest request,@Valid @RequestBody SettlementGenerateVO orders){
        return service.generateReconciliation(getSysUser(request),orders);
    }

    /**
     * 待新增对账列表
     * @author Saske
     */
    @RequestMapping(value = "/to/save/reconciliation/list",method = RequestMethod.POST)
    public Wrapper<PageData<ToBeSubmitReconciliationVO>> toBeSaveReconciliationList(HttpServletRequest request,@Valid @RequestBody ToBeSaveReconciliationListVO toBeSaveReconciliationListVO){
        return service.pageCreatedReconciliation(getSysUser(request),toBeSaveReconciliationListVO);
    }

    /**
     * 新增对账单
     * @author Saske
     */
    @RequestMapping(value = "/save/reconciliation",method = RequestMethod.POST)
    public Wrapper<Long> save(HttpServletRequest request, @Valid @RequestBody ReconciliationSaveVo saveVo){
        UserLoginCacheDTO sysUser = this.getSysUser(request);
        return service.save(sysUser,saveVo);

    }

    /**
     * 修改对账单
     * @author Saske
     */
    @RequestMapping(value = "/update/reconciliation",method = RequestMethod.POST)
    public Wrapper<Long> update(HttpServletRequest request, @Valid @RequestBody ReconciliationUpdateVo updateVo){
        return service.update(getSysUser(request),updateVo);
    }

    /**
     * 删除对账单
     * @author Saske
     */
    @RequestMapping(value = "/delete/reconciliation",method = RequestMethod.POST)
    public Wrapper<Long> deleteReconciliation( HttpServletRequest request, @RequestBody ReconciliationSubmitVo reconciliationVo){
        return service.delete(getSysUser(request),reconciliationVo);
    }

    /**
     * 提交对账单
     * @author Saske
     */
    @RequestMapping(value = "/submit/reconciliation",method = RequestMethod.POST)
    public Wrapper<Long> submitReconciliation( HttpServletRequest request,@Valid @RequestBody ReconciliationSubmitVo submitVo){
        return service.submitReconciliation(getSysUser(request),submitVo);
    }

    /**
     * 查看对账单详情
     * @author Saske
     */
    @RequestMapping(value = "/detail/reconciliation",method = RequestMethod.GET)
    public Wrapper<ToBeSubmitReconciliationDetailVO> detailReconciliation( HttpServletRequest request,@Valid ReconciliationDetailVO reconciliationDetailVO){
        return service.getInfo(getSysUser(request),reconciliationDetailVO);
    }

    /**
     * 查看对账单行明细列表
     * @author Saske
     */
    @RequestMapping(value = "/reconciliation/row/list",method = RequestMethod.GET)
    public Wrapper<PageData<ToBeSubmitReconciliationRowVO>> reconciliationRowList(HttpServletRequest request, @Valid ReconciliationDetailVO reconciliationDetailVO){
        return detailService.findDetails(getSysUser(request),reconciliationDetailVO);
    }

    /**
     * 对账单列表-收款方为当前登录会员（会员角色为服务提供者）
     * @author Saske
     */
    @RequestMapping(value = "/vendor/reconciliation/list",method = RequestMethod.GET)
    public Wrapper<PageData<ToBeSubmitReconciliationVO>> reconciliationList( HttpServletRequest request, ReconciliationListVO reconciliationListVO){
        return service.pageVendorReconciliation(getSysUser(request),reconciliationListVO);
    }

    /**
     * 对账单列表导出
     * @author Saske
     */
    @RequestMapping(value = "/vendor/reconciliation/export", method = RequestMethod.GET)
    public void exportReconciliation(HttpServletResponse response, ReconciliationListVO reconciliationListVO, String token) {
        service.exportVendorReconciliation(response,reconciliationListVO,token);
    }

    /**
     * （对账单查询页面）获取前端页面下拉框列表
     * @param request Http头部信息
     * @return 查询结果
     */
    @RequestMapping(value = "/item/reconciliation/status",method = RequestMethod.GET)
    public Wrapper<List<DropdownItem>> getStatusList( HttpServletRequest request){
        return service.getStatusList(getSysUser(request));
    }

    /**
     * （对账单查询页面）获取前端页面下拉框列表
     * @param request Http头部信息
     * @return 查询结果
     */
    @RequestMapping(value = "/item/pay/type",method = RequestMethod.GET)
    public Wrapper<List<DropdownItem>> getPayTypeList( HttpServletRequest request){
        return service.getPayTypeList(getSysUser(request));
    }
}
